﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Koala.Pro.CodeGenerator.UI.Common
{
    [Serializable]
    public class MainSetting
    {
        private const string MAIN_SETTING_FILE = "MainSetting.xml";

        private string rootNameSpace;

        private string outputDir;

        private string noPrefixOfTableName;

        private string databaseType;

        public string DatabaseType
        {
            get
            {
                return databaseType;
            }
            set
            {
                databaseType = value;
            }
        }

        public string RootNameSpace
        {
            get
            {
                return rootNameSpace;
            }
            set
            {
                rootNameSpace = value;
            }
        }

        public string OutputDir
        {
            get
            {
                return outputDir;
            }
            set
            {
                outputDir = value;
            }
        }

        public string NoPrefixOfTableName
        {
            get
            {
                return noPrefixOfTableName;
            }
            set
            {
                noPrefixOfTableName = value;
            }
        }

        public void Load()
        {
            MainSetting mainSetting = new MainSetting();
            try
            {
                mainSetting = XmlUtils.LoadObjectFromXml("MainSetting.xml", typeof(MainSetting)) as MainSetting;
                RootNameSpace = mainSetting.RootNameSpace;
                OutputDir = mainSetting.OutputDir;
                NoPrefixOfTableName = mainSetting.NoPrefixOfTableName;
                DatabaseType = mainSetting.DatabaseType;
            }
            catch
            {
            }
        }

        public bool Save()
        {
            bool result = false;
            try
            {
                XmlUtils.SaveObjectToXml("MainSetting.xml", this);
                result = true;
            }
            catch
            {
            }
            return result;
        }
    }

}
